import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Objects;

/**
 * 队列接口
 */
interface QQueue<T> {

    boolean isEmpty();

    void enquenu(T x);

    T dequeue();
}

class SeqQueue<T> implements QQueue<T> {

    public Object element[];
    public int front, rear;

    // 构造容量为length的空队列
    public SeqQueue(int length) {
        if (length < 64)
            length = 64;
        this.element = new Object[Math.abs(length)];
        this.front = this.rear = 0;
    }


    public SeqQueue() {
        this(64);
    }


    public boolean isEmpty() {
        return this.front == this.rear;
    }

    @Override
    public void enquenu(T x) {
        if (x == null)
            return;
        if (this.front == (this.rear + 1) % this.element.length) {
            Object[] temp = this.element;
            this.element = new Object[temp.length * 2];
            int i = this.front, j = 0;
            while (i != this.rear) {
                this.element[j] = temp[i];
                i = (i + 1) % temp.length;
                j++;
            }
            this.front = 0;
            this.rear = j;
        }
        this.element[this.rear] = x;
        this.rear = (this.rear + 1) % this.element.length;

    }

    @Override

    public T dequeue() {
        if (isEmpty())
            return null;
        @SuppressWarnings("unchecked")
        T temp = (T) this.element[front];
        this.front = (this.front + 1) % this.element.length;
        return temp;
    }


    public String toString() {
        String str = "(";
        if (!isEmpty()) {
            str = this.element[this.front].toString();
            int i = (this.front + 1) % this.element.length;
            while (i != this.rear) {
                str += "," + this.element[i].toString();
                i = (i + 1) % this.element.length;
            }
        }
        return str += ")";
    }
}

public class PPP {
    public static void main(String[] args) throws IOException {
        BufferedReader scanner = new BufferedReader(new InputStreamReader(System.in));
        String s;
        s = scanner.readLine();
        StringBuilder res = new StringBuilder();
        SeqQueue<String> queue = new SeqQueue<>();
        while (!s.trim().equals("E")){
            String[] temp = s.split(" ");
            StringBuilder tempStr = new StringBuilder();
            if(Objects.equals(temp[0], "A")){
                for(int i = 1;i< temp.length;i++){
                    if(i == temp.length - 1){
                        tempStr.append(temp[i]);
                    }else {
                        tempStr.append(temp[i]).append(" ");
                    }
                }
                queue.enquenu(String.valueOf(tempStr));
            }else if (Objects.equals(temp[0], "B")){
                res.append(queue.dequeue()).append(" ").append('\n');
            }
            s = scanner.readLine();
        }
        System.out.print(res.append(queue.rear-queue.front)+" "+'\n');
    }
}
